<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>高血压规范核查结果统计</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="css/all.min.css">
    <script src="css/chart.js"></script>
    <style>
        :root {
            --primary-color: #4A90E2;
            --secondary-color: #50E3C2;
            --accent-color: #F5A623;
            --dark-color: #1A535C;
            --light-bg: #F0F8FF;
            --card-bg: #FFFFFF;
            --text-dark: #2D3142;
            --text-light: #FFFFFF;
            --success-color: #4CAF50;
            --warning-color: #FF9800;
            --danger-color: #F44336;
            --info-color: #2196F3;
        }
        
        body {
            background: linear-gradient(135deg, #87CEEB 0%, #4A90E2 50%, #5DADE2 100%);
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            padding-top: 20px;
            color: var(--text-dark);
            min-height: 100vh;
        }
        
        .container {
            background-color: rgba(255, 255, 255, 0.95);
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
            padding: 25px;
            margin-bottom: 30px;
        }
        
        .header {
            background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
            color: var(--text-light);
            border-radius: 15px;
            padding: 25px;
            margin-bottom: 30px;
            box-shadow: 0 8px 20px rgba(0,0,0,0.2);
            text-shadow: 1px 1px 3px rgba(0,0,0,0.3);
        }
        
        .card {
            border-radius: 15px;
            box-shadow: 0 6px 15px rgba(0,0,0,0.1);
            transition: transform 0.3s, box-shadow 0.3s;
            margin-bottom: 25px;
            border: none;
            background-color: var(--card-bg);
            height: 100%;
        }
        
        .card:hover {
            transform: translateY(-8px);
            box-shadow: 0 12px 25px rgba(0,0,0,0.15);
        }
        
        .card-header {
            background: linear-gradient(to right, var(--secondary-color), var(--primary-color));
            color: var(--text-light);
            border-bottom: none;
            font-weight: 700;
            padding: 15px 20px;
            border-radius: 15px 15px 0 0 !important;
        }
        
        .stat-card {
            text-align: center;
            padding: 12px 12px;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            height: 100%;
        }
        
        .stat-card h2 {
            font-weight: 800;
            font-size: 2.2rem;
            margin: 10px 0;
        }
        
        .stat-card .card-title {
            font-size: 1rem;
            color: var(--text-dark);
            font-weight: 600;
        }
        
        .stat-value {
            font-size: 1.8rem;
            font-weight: 700;
            margin: 5px 0;
        }
        
        .badge {
            font-weight: 600;
            padding: 6px 12px;
            border-radius: 20px;
        }
        
        .progress {
            height: 10px;
            margin-top: 8px;
            border-radius: 10px;
            background-color: #e9ecef;
        }
        
        .progress-bar {
            border-radius: 10px;
        }
        
        .analysis-container {
            background-color: var(--light-bg);
            border-radius: 15px;
            padding: 20px;
            margin-top: 20px;
            box-shadow: 0 4px 10px rgba(0,0,0,0.05);
        }
        
        .analysis-item {
            margin-bottom: 15px;
            padding-bottom: 15px;
            border-bottom: 1px dashed #dee2e6;
        }
        
        .analysis-item:last-child {
            border-bottom: none;
            margin-bottom: 0;
            padding-bottom: 0;
        }
        
        .analysis-title {
            font-weight: 700;
            color: var(--dark-color);
            margin-bottom: 5px;
        }
        
        .analysis-content {
            color: var(--text-dark);
        }
        
        .chart-container {
            height: 350px;
            position: relative;
            margin-bottom: 25px;
        }
        
        .pie-chart-container {
            height: 280px;
            position: relative;
        }
        
        .table-container {
            overflow-x: auto;
            border-radius: 10px;
            box-shadow: 0 4px 10px rgba(0,0,0,0.05);
            background-color: white;
            margin-top: 20px;
        }
        
        .table thead th {
            background: linear-gradient(to right, var(--secondary-color), var(--primary-color));
            color: var(--text-light);
            position: sticky;
            top: 0;
            vertical-align: middle;
            font-weight: 600;
            padding: 12px 15px;
        }
        
        .table tbody td {
            padding: 12px 15px;
            vertical-align: middle;
        }
        
        .table-hover tbody tr:hover {
            background-color: rgba(78, 205, 196, 0.1);
        }
        
        .rate-high {
            color: var(--success-color);
            font-weight: 600;
        }
        
        .rate-medium {
            color: var(--warning-color);
            font-weight: 600;
        }
        
        .rate-low {
            color: var(--danger-color);
            font-weight: 600;
        }
        
        .table-striped tbody tr:nth-of-type(odd) {
            background-color: rgba(247, 255, 247, 0.5);
        }
        
        .table-striped tbody tr:nth-of-type(even) {
            background-color: rgba(255, 255, 255, 0.8);
        }
        
        .filter-section {
            background-color: var(--light-bg);
            border-radius: 15px;
            padding: 20px;
            margin-bottom: 25px;
            box-shadow: 0 4px 10px rgba(0,0,0,0.05);
        }
        
        .btn-custom {
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            color: white;
            border: none;
            font-weight: 600;
            border-radius: 10px;
            padding: 10px 20px;
        }
        
        .btn-custom:hover {
            background: linear-gradient(to right, var(--secondary-color), var(--primary-color));
            color: white;
            box-shadow: 0 4px 10px rgba(0,0,0,0.1);
        }

        .stat-card .card-title {
            color: var(--primary-color);
            font-weight: 600;
        }

        .stat-card .stat-value {
            color: var(--primary-color);
            font-weight: 700;
        }
        
        footer {
            margin-top: 40px;
            padding: 20px 0;
            color: var(--text-dark);
            font-size: 0.9rem;
        }
        
        @media (max-width: 768px) {
            .container {
                padding: 15px;
            }
            
            .header {
                padding: 15px;
            }
            
            .stat-card h2 {
                font-size: 1.8rem;
            }
            
            .chart-container {
                height: 300px;
            }
            
            .pie-chart-container {
                height: 250px;
            }
        }

        /* 修改统计卡片背景色 - 淡浅色方案 */
        .col-md-2:nth-child(1) .card {
            background: linear-gradient(135deg, #E8F4FF 0%, #D4EAFF 100%);
        }
        
        .col-md-2:nth-child(2) .card {
            background: linear-gradient(135deg, #E0F7FA 0%, #D0F0F4 100%);
        }
        
        .col-md-2:nth-child(3) .card {
            background: linear-gradient(135deg, #FFF8E1 0%, #FFF3C4 100%);
        }
        
        .col-md-2:nth-child(4) .card {
            background: linear-gradient(135deg, #FFF3E0 0%, #FFEBC8 100%);
        }
        
        .col-md-2:nth-child(5) .card {
            background: linear-gradient(135deg, #FFEBEE 0%, #FFE1E5 100%);
        }
        
        .col-md-2:nth-child(6) .card {
            background: linear-gradient(135deg, #F3E5F5 0%, #EEDFF1 100%);
        }
        
        /* 更新卡片内部文字样式 */
        .stat-card .card-title,
        .stat-card .stat-value,
        .stat-card span {
            color: var(--text-dark) !important;
            text-shadow: none;
        }
        
        /* 调整徽章样式 */
        .stat-card .badge {
            background-color: rgba(255,255,255,0.7) !important;
            color: var(--primary-color) !important;
            border: 1px solid rgba(0,0,0,0.1);
            font-weight: 700;
        }
        
        /* 进度条样式优化 */
        .stat-card .progress {
            background-color: rgba(0,0,0,0.08) !important;
            height: 12px;
            border-radius: 15px;
            box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
        }
        
        /* 进度条颜色增强 */
        #totalStandardProgress.bg-info {
            background-color: var(--info-color) !important;
        }
        
        #lastBpProgress.bg-success {
            background-color: var(--success-color) !important;
        }
        
        #consistentProgress.bg-warning {
            background-color: var(--warning-color) !important;
        }
        
        #followupProgress.bg-danger {
            background-color: var(--danger-color) !important;
        }
        
        #physicalProgress {
            background-color: var(--primary-color) !important;
        }
        
        /* 卡片悬停效果增强 */
        .card:hover {
            box-shadow: 0 15px 30px rgba(0,0,0,0.2);
            transform: translateY(-10px);
        }
        
        /* 卡片标题颜色调整 */
        .stat-card .card-title {
            color: var(--dark-color) !important;
            font-weight: 700;
        }
        
        .stat-card .stat-value {
            color: var(--primary-color) !important;
            font-weight: 800;
        }
    </style>
</head>
<body>
    <div class="container">
        <!-- 标题区域 -->
        <div class="header text-center">
            <h1><i class="fas fa-heartbeat me-2"></i>高血压规范核查结果统计</h1>
            <p class="mb-0">各管辖区域高血压患者管理情况与规范核查数据</p>
        </div>
        
        <!-- 筛选区域 -->
        <div class="filter-section">
            <div class="row g-3">
                <div class="col-md-6">
                    <div class="input-group">
                        <span class="input-group-text"><i class="fas fa-search"></i></span>
                        <input type="text" id="searchInput" class="form-control" placeholder="搜索所属管辖区域...">
                    </div>
                </div>
                <div class="col-md-3">
                    <select id="regionFilter" class="form-select">
                        <option value="">所有区域</option>
                        <!-- 区域选项将通过JS动态添加 -->
                    </select>
                </div>
                <div class="col-md-3">
                    <button id="resetFilters" class="btn btn-custom w-100">
                        <i class="fas fa-sync-alt me-1"></i>重置筛选
                    </button>
                </div>
            </div>
        </div>
        
        <!-- 统计卡片 -->
        <div class="row">
            <div class="col-md-2">
                <div class="card stat-card">
                    <div class="card-body">
                        <h5 class="card-title">高血压管理总数</h5>
                        <h2 id="totalHypertension" class="text-primary">0</h2>
                        <div class="mt-3">
                            <span class="badge bg-primary">65岁以上: <span id="total65Plus">0</span></span>
                            <span class="badge bg-secondary ms-1">65岁以下: <span id="totalBelow65">0</span></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-2">
                <div class="card stat-card">
                    <div class="card-body">
                        <h5 class="card-title">总规范率</h5>
                        <div class="stat-value text-info" id="totalStandardValue">0%</div>
                        <div class="mt-2">
                            <span>规范数: <span id="totalStandardCount">0</span></span>
                        </div>
                        <div class="progress">
                            <div id="totalStandardProgress" class="progress-bar bg-info" role="progressbar" style="width: 0%"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-2">
                <div class="card stat-card">
                    <div class="card-body">
                        <h5 class="card-title">末次血压达标率</h5>
                        <div class="stat-value text-success" id="lastBpValue">0%</div>
                        <div class="mt-2">
                            <span>达标数: <span id="lastBpCount">0</span></span>
                        </div>
                        <div class="progress">
                            <div id="lastBpProgress" class="progress-bar bg-success" role="progressbar" style="width: 0%"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-2">
                <div class="card stat-card">
                    <div class="card-body">
                        <h5 class="card-title">一致率</h5>
                        <div class="stat-value text-warning" id="consistentValue">0%</div>
                        <div class="mt-2">
                            <span>一致数: <span id="consistentCount">0</span></span>
                        </div>
                        <div class="progress">
                            <div id="consistentProgress" class="progress-bar bg-warning" role="progressbar" style="width: 0%"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-2">
                <div class="card stat-card">
                    <div class="card-body">
                        <h5 class="card-title">随访规范率</h5>
                        <div class="stat-value text-danger" id="followupValue">0%</div>
                        <div class="mt-2">
                            <span>规范数: <span id="followupCount">0</span></span>
                        </div>
                        <div class="progress">
                            <div id="followupProgress" class="progress-bar bg-danger" role="progressbar" style="width: 0%"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-2">
                <div class="card stat-card">
                    <div class="card-body">
                        <h5 class="card-title">体检表规范率</h5>
                        <div class="stat-value text-primary" id="physicalValue">0%</div>
                        <div class="mt-2">
                            <span>规范数: <span id="physicalCount">0</span></span>
                        </div>
                        <div class="progress">
                            <div id="physicalProgress" class="progress-bar" style="background-color: var(--primary-color); width: 0%" role="progressbar"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 数据分析区域 -->
        <div class="analysis-container">
            <h4><i class="fas fa-chart-line me-2"></i>全部数据初步分析结果</h4>
            <div class="row mt-3">
                <div class="col-md-6">
                    <div class="analysis-item">
                        <div class="analysis-title">总规范率分析</div>
                        <div class="analysis-content" id="totalStandardAnalysis">加载中...</div>
                    </div>
                    <div class="analysis-item">
                        <div class="analysis-title">末次血压达标率分析</div>
                        <div class="analysis-content" id="lastBpAnalysis">加载中...</div>
                    </div>
                    <div class="analysis-item">
                        <div class="analysis-title">一致性问题分析</div>
                        <div class="analysis-content" id="consistencyAnalysis">加载中...</div>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="analysis-item">
                        <div class="analysis-title">随访规范率分析</div>
                        <div class="analysis-content" id="followupAnalysis">加载中...</div>
                    </div>
                    <div class="analysis-item">
                        <div class="analysis-title">体检表问题分析</div>
                        <div class="analysis-content" id="physicalAnalysis">加载中...</div>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 图表区域 -->
        <div class="row mt-4">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <i class="fas fa-chart-bar me-2"></i>各区域高血压管理人数分布
                    </div>
                    <div class="card-body">
                        <div class="chart-container">
                            <canvas id="regionChart"></canvas>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="row mt-4">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <i class="fas fa-chart-bar me-2"></i>规范率对比
                    </div>
                    <div class="card-body">
                        <div class="chart-container">
                            <canvas id="rateChart"></canvas>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 饼图区域 -->
        <div class="row mt-4">
            <div class="col-md-4">
                <div class="card">
                    <div class="card-header">
                        <i class="fas fa-chart-pie me-2"></i>数据不一致类型分布
                    </div>
                    <div class="card-body">
                        <div class="pie-chart-container">
                            <canvas id="inconsistencyChart"></canvas>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="card">
                    <div class="card-header">
                        <i class="fas fa-chart-pie me-2"></i>体检表问题分布
                    </div>
                    <div class="card-body">
                        <div class="pie-chart-container">
                            <canvas id="physicalIssuesChart"></canvas>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="card">
                    <div class="card-header">
                        <i class="fas fa-chart-pie me-2"></i>随访问题分布
                    </div>
                    <div class="card-body">
                        <div class="pie-chart-container">
                            <canvas id="followupIssuesChart"></canvas>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 数据表格 -->
        <div class="card mt-4">
            <div class="card-header d-flex justify-content-between align-items-center">
                <div>
                    <i class="fas fa-table me-2"></i>详细数据
                </div>
                <div class="text-muted small">
                    共 <span id="totalCount">0</span> 条记录
                </div>
            </div>
            <div class="card-body p-0">
                <div class="table-container">
                    <table class="table table-hover table-striped mb-0">
                        <thead>
                            <tr>
                                <th class="sortable" data-sort="region">所属管辖</th>
                                <th class="sortable" data-sort="hypertension_total">高血压管理数</th>
                                <th class="sortable" data-sort="age_65_plus">65及以上数</th>
                                <th class="sortable" data-sort="age_below_65">65以下数</th>
                                <th class="sortable" data-sort="last_bp_standard">末次血压达标数</th>
                                <th class="sortable" data-sort="last_bp_standard_rate">末次血压达标率</th>
                                <th class="sortable" data-sort="total_standard">总规范数</th>
                                <th class="sortable" data-sort="total_standard_rate">总规范率</th>
                                <th class="sortable" data-sort="consistent_rate">一致率</th>
                                <th class="sortable" data-sort="physical_standard_rate">体检表规范率</th>
                                <th class="sortable" data-sort="followup_standard_rate">随访规范率</th>
                            </tr>
                        </thead>
                        <tbody id="dataBody">
                            <!-- 数据将通过JS动态填充 -->
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        
        <!-- 页脚 -->
        <footer class="text-center">
            <p>数据更新时间: <span id="updateTime"></span></p>
            <p class="small">© 高血压规范核查统计系统 - 郁进</p>
        </footer>
    </div>

    <!-- 内联JSON数据 -->
    <script id="jsonData" type="application/json">
   [
  {
    "region": "万庄村委会",
    "hypertension_total": 378,
    "age_65_plus": 288,
    "age_below_65": 90,
    "last_bp_standard": 297,
    "last_bp_standard_rate": 0.7857,
    "total_standard": 332,
    "total_standard_rate": 0.8783,
    "consistent_count": 367,
    "consistent_rate": 0.9709,
    "inconsistent_count": 11,
    "history_inconsistent": 2,
    "same_day_followup_inconsistent": 0,
    "same_day_double_disease_inconsistent": 0,
    "physical_drug_inconsistent": 9,
    "physical_exam_total": 335,
    "public_health_exam": 0,
    "other_exam": 335,
    "below_65_unexamined": 0,
    "health_issues": 0,
    "health_assessment_issues": 4,
    "health_guidance_issues": 4,
    "other_physical_issues": 0,
    "physical_standard_count": 334,
    "physical_standard_rate": 0.997,
    "followup_frequency_noncompliance": 27,
    "referral_issues": 7,
    "followup_missing_errors": 1,
    "followup_standard_count": 343,
    "followup_standard_rate": 0.9074
  },
  {
    "region": "万杨村委会",
    "hypertension_total": 510,
    "age_65_plus": 389,
    "age_below_65": 121,
    "last_bp_standard": 422,
    "last_bp_standard_rate": 0.8275,
    "total_standard": 476,
    "total_standard_rate": 0.9333,
    "consistent_count": 501,
    "consistent_rate": 0.9824,
    "inconsistent_count": 9,
    "history_inconsistent": 2,
    "same_day_followup_inconsistent": 5,
    "same_day_double_disease_inconsistent": 1,
    "physical_drug_inconsistent": 2,
    "physical_exam_total": 458,
    "public_health_exam": 0,
    "other_exam": 458,
    "below_65_unexamined": 4,
    "health_issues": 0,
    "health_assessment_issues": 8,
    "health_guidance_issues": 7,
    "other_physical_issues": 16,
    "physical_standard_count": 450,
    "physical_standard_rate": 0.9825,
    "followup_frequency_noncompliance": 10,
    "referral_issues": 5,
    "followup_missing_errors": 4,
    "followup_standard_count": 491,
    "followup_standard_rate": 0.9627
  },
  {
    "region": "中桥村委会",
    "hypertension_total": 426,
    "age_65_plus": 363,
    "age_below_65": 63,
    "last_bp_standard": 344,
    "last_bp_standard_rate": 0.8075,
    "total_standard": 308,
    "total_standard_rate": 0.723,
    "consistent_count": 365,
    "consistent_rate": 0.8568,
    "inconsistent_count": 61,
    "history_inconsistent": 17,
    "same_day_followup_inconsistent": 20,
    "same_day_double_disease_inconsistent": 5,
    "physical_drug_inconsistent": 23,
    "physical_exam_total": 358,
    "public_health_exam": 0,
    "other_exam": 358,
    "below_65_unexamined": 0,
    "health_issues": 0,
    "health_assessment_issues": 43,
    "health_guidance_issues": 30,
    "other_physical_issues": 7,
    "physical_standard_count": 326,
    "physical_standard_rate": 0.9106,
    "followup_frequency_noncompliance": 11,
    "referral_issues": 13,
    "followup_missing_errors": 16,
    "followup_standard_count": 387,
    "followup_standard_rate": 0.9085
  },
  {
    "region": "兴曲村委会",
    "hypertension_total": 435,
    "age_65_plus": 328,
    "age_below_65": 107,
    "last_bp_standard": 391,
    "last_bp_standard_rate": 0.8989,
    "total_standard": 320,
    "total_standard_rate": 0.7356,
    "consistent_count": 340,
    "consistent_rate": 0.7816,
    "inconsistent_count": 95,
    "history_inconsistent": 28,
    "same_day_followup_inconsistent": 21,
    "same_day_double_disease_inconsistent": 4,
    "physical_drug_inconsistent": 51,
    "physical_exam_total": 362,
    "public_health_exam": 0,
    "other_exam": 362,
    "below_65_unexamined": 1,
    "health_issues": 0,
    "health_assessment_issues": 54,
    "health_guidance_issues": 7,
    "other_physical_issues": 13,
    "physical_standard_count": 356,
    "physical_standard_rate": 0.9834,
    "followup_frequency_noncompliance": 13,
    "referral_issues": 3,
    "followup_missing_errors": 10,
    "followup_standard_count": 409,
    "followup_standard_rate": 0.9402
  },
  {
    "region": "兴花村委会",
    "hypertension_total": 356,
    "age_65_plus": 269,
    "age_below_65": 87,
    "last_bp_standard": 304,
    "last_bp_standard_rate": 0.8539,
    "total_standard": 317,
    "total_standard_rate": 0.8904,
    "consistent_count": 348,
    "consistent_rate": 0.9775,
    "inconsistent_count": 8,
    "history_inconsistent": 4,
    "same_day_followup_inconsistent": 0,
    "same_day_double_disease_inconsistent": 1,
    "physical_drug_inconsistent": 3,
    "physical_exam_total": 320,
    "public_health_exam": 0,
    "other_exam": 320,
    "below_65_unexamined": 1,
    "health_issues": 0,
    "health_assessment_issues": 10,
    "health_guidance_issues": 4,
    "other_physical_issues": 2,
    "physical_standard_count": 310,
    "physical_standard_rate": 0.9688,
    "followup_frequency_noncompliance": 15,
    "referral_issues": 11,
    "followup_missing_errors": 0,
    "followup_standard_count": 331,
    "followup_standard_rate": 0.9298
  }
]
    </script>

    <script>
        // 全局变量
        let originalData = [];
        let filteredData = [];
        let currentSort = { column: 'region', direction: 'asc' };
        let regionChartInstance = null;
        let rateChartInstance = null;
        let inconsistencyChartInstance = null;
        let physicalIssuesChartInstance = null;
        let followupIssuesChartInstance = null;

        // 页面加载完成后执行
        document.addEventListener('DOMContentLoaded', function() {
            // 设置更新时间
            document.getElementById('updateTime').textContent = new Date().toLocaleString();
            
            // 加载数据
            loadData();
            
            // 设置事件监听器
            document.getElementById('searchInput').addEventListener('input', filterData);
            document.getElementById('regionFilter').addEventListener('change', filterData);
            document.getElementById('resetFilters').addEventListener('click', resetFilters);
            
            // 设置表格排序
            document.querySelectorAll('.sortable').forEach(header => {
                header.addEventListener('click', function() {
                    sortTable(this.dataset.sort);
                });
            });
        });

        // 加载JSON数据
        function loadData() {
            try {
                // 从内联脚本获取JSON数据
                const jsonDataElement = document.getElementById('jsonData');
                originalData = JSON.parse(jsonDataElement.textContent);
                filteredData = [...originalData];
                
                // 填充区域筛选器
                populateRegionFilter();
                
                // 更新统计数据
                updateStatistics();
                
                // 生成分析报告
                generateAnalysisReport();
                
                // 渲染表格 - 确保按原始region顺序
                renderTable();
                
                // 渲染图表 - 确保按原始region顺序
                renderCharts();
                
            } catch (error) {
                console.error('加载数据失败:', error);
                document.getElementById('dataBody').innerHTML = `
                    <tr>
                        <td colspan="11" class="text-center text-danger">
                            <i class="fas fa-exclamation-triangle me-2"></i>数据加载失败，请刷新页面重试
                        </td>
                    </tr>
                `;
            }
        }
        
        // 填充区域筛选器
        function populateRegionFilter() {
            const regionFilter = document.getElementById('regionFilter');
            const regions = [...new Set(originalData.map(item => item.region))].sort();
            
            regions.forEach(region => {
                const option = document.createElement('option');
                option.value = region;
                option.textContent = region;
                regionFilter.appendChild(option);
            });
        }

        // 更新统计数据
        function updateStatistics() {
            // 计算总数
            const totalHypertension = filteredData.reduce((sum, item) => sum + item.hypertension_total, 0);
            const total65Plus = filteredData.reduce((sum, item) => sum + item.age_65_plus, 0);
            const totalBelow65 = filteredData.reduce((sum, item) => sum + item.age_below_65, 0);
            
            document.getElementById('totalHypertension').textContent = totalHypertension.toLocaleString();
            document.getElementById('total65Plus').textContent = total65Plus.toLocaleString();
            document.getElementById('totalBelow65').textContent = totalBelow65.toLocaleString();
            
            // 计算总和
            const totalStandardSum = filteredData.reduce((sum, item) => sum + item.total_standard, 0);
            const lastBpStandardSum = filteredData.reduce((sum, item) => sum + item.last_bp_standard, 0);
            const consistentCountSum = filteredData.reduce((sum, item) => sum + item.consistent_count, 0);
            const followupStandardCountSum = filteredData.reduce((sum, item) => sum + item.followup_standard_count, 0);
            const physicalStandardCountSum = filteredData.reduce((sum, item) => sum + item.physical_standard_count, 0);
            
            // 计算比率（总和相除）
            const totalStandardRate = totalStandardSum / totalHypertension;
            const lastBpRate = lastBpStandardSum / totalHypertension;
            const consistentRate = consistentCountSum / totalHypertension;
            const followupRate = followupStandardCountSum / totalHypertension;
            const physicalRate = physicalStandardCountSum / totalHypertension;
            
            // 计算具体数值（保持不变）
            const totalStandardCount = filteredData.reduce((sum, item) => sum + item.total_standard, 0);
            const lastBpCount = filteredData.reduce((sum, item) => sum + item.last_bp_standard, 0);
            const consistentCount = filteredData.reduce((sum, item) => sum + item.consistent_count, 0);
            const followupCount = filteredData.reduce((sum, item) => sum + item.followup_standard_count, 0);
            const physicalCount = filteredData.reduce((sum, item) => sum + item.physical_standard_count, 0);
            
            document.getElementById('totalStandardValue').textContent = (totalStandardRate * 100).toFixed(1) + '%';
            document.getElementById('lastBpValue').textContent = (lastBpRate * 100).toFixed(1) + '%';
            document.getElementById('consistentValue').textContent = (consistentRate * 100).toFixed(1) + '%';
            document.getElementById('physicalValue').textContent = (physicalRate * 100).toFixed(1) + '%';
            document.getElementById('followupValue').textContent = (followupRate * 100).toFixed(1) + '%';
            
            document.getElementById('totalStandardCount').textContent = totalStandardCount.toLocaleString();
            document.getElementById('lastBpCount').textContent = lastBpCount.toLocaleString();
            document.getElementById('consistentCount').textContent = consistentCount.toLocaleString();
            document.getElementById('followupCount').textContent = followupCount.toLocaleString();
            document.getElementById('physicalCount').textContent = physicalCount.toLocaleString();
            
            // 更新进度条
            document.getElementById('totalStandardProgress').style.width = (totalStandardRate * 100) + '%';
            document.getElementById('lastBpProgress').style.width = (lastBpRate * 100) + '%';
            document.getElementById('consistentProgress').style.width = (consistentRate * 100) + '%';
            document.getElementById('physicalProgress').style.width = (physicalRate * 100) + '%';
            document.getElementById('followupProgress').style.width = (followupRate * 100) + '%';
            
            // 更新总记录数
            document.getElementById('totalCount').textContent = filteredData.length;
        }

        // 生成分析报告
        function generateAnalysisReport() {
            // 总规范率分析- 修改为显示前3名和后3名
            const standardRateData = originalData.map(item => ({
            region: item.region,
            rate: item.total_standard_rate
            }));
            
            // 按规范率排序（从高到低）
            standardRateData.sort((a, b) => b.rate - a.rate);
            
            // 获取前3名和后3名
            const top3 = standardRateData.slice(0, 3);
            const bottom3 = standardRateData.slice(-3).reverse(); // 反向排序，从最差开始
            
            // 构建前3名显示字符串
            let top3Html = top3.map(item => 
                `<span class="rate-high">${item.region}(${(item.rate * 100).toFixed(1)}%)</span>`
            ).join('、');
            
            // 构建后3名显示字符串
            let bottom3Html = bottom3.map(item => 
                `<span class="rate-low">${item.region}(${(item.rate * 100).toFixed(1)}%)</span>`
            ).join('、');
            
            document.getElementById('totalStandardAnalysis').innerHTML = `
                最佳: ${top3Html}<br>
                偏低: ${bottom3Html}
            `;
            
            // 末次血压达标率分析
            const lastBpRates = originalData.map(item => item.last_bp_standard_rate);
            const highBpRegions = originalData.filter(item => item.last_bp_standard_rate > 0.8)
                .map(item => `${item.region}(${(item.last_bp_standard_rate * 100).toFixed(1)}%)`);
            const lowBpRegions = originalData.filter(item => item.last_bp_standard_rate < 0.3)
                .map(item => `${item.region}(${(item.last_bp_standard_rate * 100).toFixed(1)}%)`);
            
            let bpAnalysis = '';
            if (highBpRegions.length > 0) {
                bpAnalysis += `<span class="rate-high">偏高(>80%): ${highBpRegions.join(', ')}</span>。`;
            }
            if (lowBpRegions.length > 0) {
                bpAnalysis += `<span class="rate-low">偏低(<30%): ${lowBpRegions.join(', ')}</span>`;
            }
            if (bpAnalysis === '') {
                bpAnalysis = '各区域末次血压达标率均在正常范围内';
            }
            
            document.getElementById('lastBpAnalysis').innerHTML = bpAnalysis;
            
            // 一致性问题分析 - 包含所有问题
            const totalInconsistent = originalData.reduce((sum, item) => sum + item.inconsistent_count, 0);
            const historyInconsistent = originalData.reduce((sum, item) => sum + item.history_inconsistent, 0);
            const sameDayFollowup = originalData.reduce((sum, item) => sum + item.same_day_followup_inconsistent, 0);
            const sameDayDisease = originalData.reduce((sum, item) => sum + item.same_day_double_disease_inconsistent, 0);
            const physicalDrug = originalData.reduce((sum, item) => sum + item.physical_drug_inconsistent, 0);
            
            document.getElementById('consistencyAnalysis').innerHTML = `
                总不一致数: ${totalInconsistent}，
                具体分布如下：
                <ul>
                    <li>三史不一致数: ${historyInconsistent}</li>
                    <li>同天随访体检不一致数: ${sameDayFollowup}</li>
                    <li>同天两病随访不一致数: ${sameDayDisease}</li>
                    <li>体检与用药不一致数: ${physicalDrug}</li>
                </ul>
            `;
            
            // 随访规范率分析 - 包含规范率小于80%的所有单位
            const followupRates = originalData.map(item => item.followup_standard_rate);
            const avgFollowupRate = followupRates.reduce((sum, rate) => sum + rate, 0) / followupRates.length;
            const followupFrequency = originalData.reduce((sum, item) => sum + item.followup_frequency_noncompliance, 0);
            const referralIssues = originalData.reduce((sum, item) => sum + item.referral_issues, 0);
            const followupErrors = originalData.reduce((sum, item) => sum + item.followup_missing_errors, 0);
            
            // 筛选随访规范率小于80%的单位
            const lowFollowupRegions = originalData
                .filter(item => item.followup_standard_rate < 0.8)
                .map(item => `${item.region}(${(item.followup_standard_rate * 100).toFixed(1)}%)`);
            
            let followupAnalysis = `
                平均随访规范率: ${(avgFollowupRate * 100).toFixed(1)}%，
                主要问题: <span class="rate-medium">${followupFrequency}例随访频次不达标</span>，
                ${referralIssues}例转诊增访问题，
                ${followupErrors}例随访空错项。
            `;
            
            if (lowFollowupRegions.length > 0) {
                followupAnalysis += `<br><span class="rate-low">随访规范率低于80%的单位: ${lowFollowupRegions.join(', ')}</span>`;
            } else {
                followupAnalysis += '<br>所有单位随访规范率均达到80%以上';
            }
            
            document.getElementById('followupAnalysis').innerHTML = followupAnalysis;
            
            // 体检表问题分析 - 包含所有问题
            const healthAssessment = originalData.reduce((sum, item) => sum + item.health_assessment_issues, 0);
            const healthGuidance = originalData.reduce((sum, item) => sum + item.health_guidance_issues, 0);
            const otherPhysical = originalData.reduce((sum, item) => sum + item.other_physical_issues, 0);
            const healthIssues = originalData.reduce((sum, item) => sum + item.health_issues, 0);
            
            document.getElementById('physicalAnalysis').innerHTML = `
                总问题数: ${healthIssues + healthAssessment + healthGuidance + otherPhysical}，
                具体分布如下：
                <ul>
                    <li>现存主要健康问题数: ${healthIssues}</li>
                    <li>健康评价问题数: ${healthAssessment}</li>
                    <li>健康指导问题数: ${healthGuidance}</li>
                    <li>体检表其他问题数: ${otherPhysical}</li>
                </ul>
            `;
        }

        // 渲染表格
        function renderTable() {
            const tbody = document.getElementById('dataBody');
            tbody.innerHTML = '';
            
            if (filteredData.length === 0) {
                tbody.innerHTML = `
                    <tr>
                        <td colspan="11" class="text-center text-muted">
                            <i class="fas fa-info-circle me-2"></i>没有找到匹配的数据
                        </td>
                    </tr>
                `;
                return;
            }
            
            filteredData.forEach((item, index) => {
                const row = document.createElement('tr');
                
                // 确定比率颜色类
                const getRateClass = (rate) => {
                    if (rate >= 0.9) return 'rate-high';
                    if (rate >= 0.7) return 'rate-medium';
                    return 'rate-low';
                };
                
                // 添加主要列
                row.innerHTML = `
                    <td>${item.region}</td>
                    <td>${item.hypertension_total}</td>
                    <td>${item.age_65_plus}</td>
                    <td>${item.age_below_65}</td>
                    <td>${item.last_bp_standard}</td>
                    <td>
                        <span class="${getRateClass(item.last_bp_standard_rate)}">${(item.last_bp_standard_rate * 100).toFixed(1)}%</span>
                        <div class="progress">
                            <div class="progress-bar bg-success" role="progressbar" 
                                 style="width: ${item.last_bp_standard_rate * 100}%"></div>
                        </div>
                    </td>
                    <td>${item.total_standard}</td>
                    <td>
                        <span class="${getRateClass(item.total_standard_rate)}">${(item.total_standard_rate * 100).toFixed(1)}%</span>
                        <div class="progress">
                            <div class="progress-bar bg-info" role="progressbar" 
                                 style="width: ${item.total_standard_rate * 100}%"></div>
                        </div>
                    </td>
                    <td>
                        <span class="${getRateClass(item.consistent_rate)}">${(item.consistent_rate * 100).toFixed(1)}%</span>
                        <div class="progress">
                            <div class="progress-bar bg-warning" role="progressbar" 
                                 style="width: ${item.consistent_rate * 100}%"></div>
                        </div>
                    </td>
                    <td>
                        <span class="${getRateClass(item.physical_standard_rate)}">${(item.physical_standard_rate * 100).toFixed(1)}%</span>
                        <div class="progress">
                            <div class="progress-bar" style="background-color: var(--primary-color); width: ${item.physical_standard_rate * 100}%" role="progressbar"></div>
                        </div>
                    </td>
                    <td>
                        <span class="${getRateClass(item.followup_standard_rate)}">${(item.followup_standard_rate * 100).toFixed(1)}%</span>
                        <div class="progress">
                            <div class="progress-bar bg-danger" role="progressbar" 
                                 style="width: ${item.followup_standard_rate * 100}%"></div>
                        </div>
                    </td>
                `;
                
                tbody.appendChild(row);
            });
        }

        // 渲染图表
        function renderCharts() {
             // 销毁旧图表实例
            if (regionChartInstance) regionChartInstance.destroy();
            if (rateChartInstance) rateChartInstance.destroy();
            if (inconsistencyChartInstance) inconsistencyChartInstance.destroy();
            if (physicalIssuesChartInstance) physicalIssuesChartInstance.destroy();
            if (followupIssuesChartInstance) followupIssuesChartInstance.destroy();
            
            // 按原始region顺序排序数据
            const regionOrderMap = {};
            originalData.forEach((item, index) => {
                regionOrderMap[item.region] = index;
            });
            
            const sortedData = [...filteredData].sort((a, b) => {
                const indexA = regionOrderMap[a.region];
                const indexB = regionOrderMap[b.region];
                return indexA - indexB;
            });
            
            // 区域分布图表
            const regionCtx = document.getElementById('regionChart').getContext('2d');
            const regionLabels = sortedData.map(item => item.region);
            const regionData = sortedData.map(item => item.hypertension_total);
            
            regionChartInstance = new Chart(regionCtx, {
                type: 'bar',
                data: {
                    labels: regionLabels,
                    datasets: [{
                        label: '高血压管理人数',
                        data: regionData,
                        backgroundColor: 'rgba(74, 144, 226, 0.7)',
                        borderColor: 'rgba(74, 144, 226, 1)',
                        borderWidth: 1
                    }]
                },
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    scales: {
                        y: {
                            beginAtZero: true,
                            title: {
                                display: true,
                                text: '人数',
                                font: {
                                    size: 16,
                                    weight: 'bold'
                                }
                            },
                            ticks: {
                                font: {
                                    size: 14
                                }
                            }
                        },
                        x: {
                            title: {
                                display: true,
                                text: '所属管辖区域',
                                font: {
                                    size: 16,
                                    weight: 'bold'
                                }
                            },
                            ticks: {
                                font: {
                                    size: 14
                                }
                            }
                        }
                    },
                    plugins: {
                        legend: {
                            labels: {
                                font: {
                                    size: 16
                                }
                            }
                        },
                        tooltip: {
                            titleFont: {
                                size: 16
                            },
                            bodyFont: {
                                size: 15
                            }
                        }
                    }
                }
            });
            
            // 规范率对比图表（柱状图）
            const rateCtx = document.getElementById('rateChart').getContext('2d');
            const rateLabels = sortedData.map(item => item.region);
            
            rateChartInstance = new Chart(rateCtx, {
                type: 'bar',
                data: {
                    labels: rateLabels,
                    datasets: [
                        {
                            label: '总规范率',
                            data: sortedData.map(item => item.total_standard_rate * 100),
                            backgroundColor: 'rgba(78, 205, 196, 0.7)',
                            borderColor: 'rgba(78, 205, 196, 1)',
                            borderWidth: 1
                        },
                        {
                            label: '末次血压达标率',
                            data: sortedData.map(item => item.last_bp_standard_rate * 100),
                            backgroundColor: 'rgba(76, 175, 80, 0.7)',
                            borderColor: 'rgba(76, 175, 80, 1)',
                            borderWidth: 1
                        },
                        {
                            label: '一致率',
                            data: sortedData.map(item => item.consistent_rate * 100),
                            backgroundColor: 'rgba(255, 209, 102, 0.7)',
                            borderColor: 'rgba(255, 209, 102, 1)',
                            borderWidth: 1
                        },
                        {
                            label: '随访规范率',
                            data: sortedData.map(item => item.followup_standard_rate * 100),
                            backgroundColor: 'rgba(244, 67, 54, 0.7)',
                            borderColor: 'rgba(244, 67, 54, 1)',
                            borderWidth: 1
                        },
                        {
                            label: '体检表规范率',
                            data: sortedData.map(item => item.physical_standard_rate * 100),
                            backgroundColor: 'rgba(74, 144, 226, 0.7)',
                            borderColor: 'rgba(74, 144, 226, 1)',
                            borderWidth: 1
                        }
                    ]
                },
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    scales: {
                        y: {
                            beginAtZero: true,
                            max: 100,
                            title: {
                                display: true,
                                text: '百分比 (%)',
                                font: {
                                    size: 16,
                                    weight: 'bold'
                                }
                            },
                            ticks: {
                                font: {
                                    size: 14
                                }
                            }
                        },
                        x: {
                            title: {
                                display: true,
                                text: '所属管辖区域',
                                font: {
                                    size: 16,
                                    weight: 'bold'
                                }
                            },
                            ticks: {
                                font: {
                                    size: 14
                                }
                            }
                        }
                    },
                    plugins: {
                        legend: {
                            labels: {
                                font: {
                                    size: 16
                                }
                            }
                        },
                        tooltip: {
                            titleFont: {
                                size: 16
                            },
                            bodyFont: {
                                size: 15
                            },
                            callbacks: {
                                label: function(context) {
                                    return `${context.dataset.label}: ${context.raw.toFixed(1)}%`;
                                }
                            }
                        }
                    }
                }
            });
            
            // 数据不一致类型饼图
            const inconsistencyCtx = document.getElementById('inconsistencyChart').getContext('2d');
            const inconsistencyData = [
                filteredData.reduce((sum, item) => sum + item.history_inconsistent, 0),
                filteredData.reduce((sum, item) => sum + item.same_day_followup_inconsistent, 0),
                filteredData.reduce((sum, item) => sum + item.same_day_double_disease_inconsistent, 0),
                filteredData.reduce((sum, item) => sum + item.physical_drug_inconsistent, 0)
            ];
            
            inconsistencyChartInstance = new Chart(inconsistencyCtx, {
                type: 'pie',
                data: {
                    labels: ['三史不一致数', '同天随访体检不一致数', '同天两病随访不一致数', '体检与近期随访用药不一致数'],
                    datasets: [{
                        data: inconsistencyData,
                        backgroundColor: [
                            'rgba(74, 144, 226, 0.7)',
                            'rgba(80, 227, 194, 0.7)',
                            'rgba(245, 166, 35, 0.7)',
                            'rgba(26, 83, 92, 0.7)'
                        ],
                        borderColor: [
                            'rgba(74, 144, 226, 1)',
                            'rgba(80, 227, 194, 1)',
                            'rgba(245, 166, 35, 1)',
                            'rgba(26, 83, 92, 1)'
                        ],
                        borderWidth: 1
                    }]
                },
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    plugins: {
                        legend: {
                            position: 'bottom',
                            labels: {
                                font: {
                                    size: 14
                                }
                            }
                        },
                        tooltip: {
                            callbacks: {
                                label: function(context) {
                                    return `${context.label}: ${context.raw}`;
                                }
                            }
                        }
                    }
                }
            });
            
            // 体检表问题饼图
            const physicalIssuesCtx = document.getElementById('physicalIssuesChart').getContext('2d');
            const physicalIssuesData = [
                filteredData.reduce((sum, item) => sum + item.health_issues, 0),
                filteredData.reduce((sum, item) => sum + item.health_assessment_issues, 0),
                filteredData.reduce((sum, item) => sum + item.health_guidance_issues, 0),
                filteredData.reduce((sum, item) => sum + item.other_physical_issues, 0)
            ];
            
            physicalIssuesChartInstance = new Chart(physicalIssuesCtx, {
                type: 'pie',
                data: {
                    labels: ['现存主要健康问题数', '健康评价问题数', '健康指导问题数', '体检表其他问题数'],
                    datasets: [{
                        data: physicalIssuesData,
                        backgroundColor: [
                            'rgba(74, 144, 226, 0.7)',
                            'rgba(80, 227, 194, 0.7)',
                            'rgba(245, 166, 35, 0.7)',
                            'rgba(26, 83, 92, 0.7)'
                        ],
                        borderColor: [
                            'rgba(74, 144, 226, 1)',
                            'rgba(80, 227, 194, 1)',
                            'rgba(245, 166, 35, 1)',
                            'rgba(26, 83, 92, 1)'
                        ],
                        borderWidth: 1
                    }]
                },
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    plugins: {
                        legend: {
                            position: 'bottom',
                            labels: {
                                font: {
                                    size: 14
                                }
                            }
                        },
                        tooltip: {
                            callbacks: {
                                label: function(context) {
                                    return `${context.label}: ${context.raw}`;
                                }
                            }
                        }
                    }
                }
            });
            
            // 随访问题饼图
            const followupIssuesCtx = document.getElementById('followupIssuesChart').getContext('2d');
            const followupIssuesData = [
                filteredData.reduce((sum, item) => sum + item.followup_frequency_noncompliance, 0),
                filteredData.reduce((sum, item) => sum + item.referral_issues, 0),
                filteredData.reduce((sum, item) => sum + item.followup_missing_errors, 0)
            ];
            
            followupIssuesChartInstance = new Chart(followupIssuesCtx, {
                type: 'pie',
                data: {
                    labels: ['随访频次不达标数', '转诊增访问题数', '随访空错项数'],
                    datasets: [{
                        data: followupIssuesData,
                        backgroundColor: [
                            'rgba(74, 144, 226, 0.7)',
                            'rgba(80, 227, 194, 0.7)',
                            'rgba(245, 166, 35, 0.7)'
                        ],
                        borderColor: [
                            'rgba(74, 144, 226, 1)',
                            'rgba(80, 227, 194, 1)',
                            'rgba(245, 166, 35, 1)'
                        ],
                        borderWidth: 1
                    }]
                },
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    plugins: {
                        legend: {
                            position: 'bottom',
                            labels: {
                                font: {
                                    size: 14
                                }
                            }
                        },
                        tooltip: {
                            callbacks: {
                                label: function(context) {
                                    return `${context.label}: ${context.raw}`;
                                }
                            }
                        }
                    }
                }
            });
        }

        // 数据筛选
        function filterData() {
            const searchTerm = document.getElementById('searchInput').value.toLowerCase();
            const regionFilter = document.getElementById('regionFilter').value;
            
            filteredData = originalData.filter(item => {
                const matchesSearch = item.region.toLowerCase().includes(searchTerm);
                const matchesRegion = regionFilter ? item.region === regionFilter : true;
                return matchesSearch && matchesRegion;
            });
            
            // 重新排序
            sortTable(currentSort.column, currentSort.direction);
            
            // 更新UI
            updateStatistics();
            renderTable();
            renderCharts();
        }

        // 重置筛选
        function resetFilters() {
            document.getElementById('searchInput').value = '';
            document.getElementById('regionFilter').value = '';
            filterData();
        }

        // 表格排序
        function sortTable(column, direction = null) {
            // 确定排序方向
            if (currentSort.column === column) {
                currentSort.direction = currentSort.direction === 'asc' ? 'desc' : 'asc';
            } else {
                currentSort.column = column;
                currentSort.direction = 'asc';
            }
            
            // 更新表头样式
            document.querySelectorAll('.sortable').forEach(header => {
                header.classList.remove('asc', 'desc');
                if (header.dataset.sort === currentSort.column) {
                    header.classList.add(currentSort.direction);
                }
            });
            
            // 如果是按region排序，使用原始顺序
            if (column === 'region') {
                // 创建region到原始索引的映射
                const regionOrderMap = {};
                originalData.forEach((item, index) => {
                    regionOrderMap[item.region] = index;
                });
                
                // 按原始顺序排序
                filteredData.sort((a, b) => {
                    const indexA = regionOrderMap[a.region];
                    const indexB = regionOrderMap[b.region];
                    return currentSort.direction === 'asc' ? indexA - indexB : indexB - indexA;
                });
            } else {
                // 执行其他列的排序
                filteredData.sort((a, b) => {
                    let valueA = a[column];
                    let valueB = b[column];
                    
                    // 处理可能的空值
                    if (valueA === null || valueA === undefined) valueA = '';
                    if (valueB === null || valueB === undefined) valueB = '';
                    
                    // 数值排序
                    if (typeof valueA === 'number' && typeof valueB === 'number') {
                        return currentSort.direction === 'asc' ? valueA - valueB : valueB - valueA;
                    }
                    
                    // 字符串排序
                    valueA = String(valueA).toLowerCase();
                    valueB = String(valueB).toLowerCase();
                    
                    if (valueA < valueB) return currentSort.direction === 'asc' ? -1 : 1;
                    if (valueA > valueB) return currentSort.direction === 'asc' ? 1 : -1;
                    return 0;
                });
            }
            
            // 重新渲染表格
            renderTable();
        }
    </script>
</body>
</html>